package cn.edu.sjtu.blank.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @author loumoon
 * @date 2019-11-29 15:19
 */
@Service
public class BlankServiceImpl {
    @Autowired
    private RestTemplate restTemplate;
    @Value("${blank.data.source.url}")
    private String dataSourceUrl;
    @Value("${blank.identifier}")
    private Integer blankIdentifier;

    public JSONObject detectStatus() {
        ResponseEntity<JSONObject> responseEntity = restTemplate.getForEntity(dataSourceUrl + "?num={1}", JSONObject.class, blankIdentifier);
        return responseEntity.getBody();
    }

    public JSONObject initiate() {
        JSONObject requestParam = new JSONObject();
        requestParam.put("num", blankIdentifier);
        ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity(dataSourceUrl, requestParam, JSONObject.class);
        return responseEntity.getBody();
    }
}
